
cd "C:\Users\Dell\Dropbox\newdemwar (2)\Encyclopedia\Replication Data"

clear
use "msdydronewsort.dta"

rename rod5l 	ComDeml
rename rod5s 	ComDems
rename roan5l 	IncDeml
rename roan5s 	IncDems
rename roat5l 	ComAutl
rename roat5s 	ComAuts
rename rodn5l 	IncAutl
rename rodn5s	IncAuts
rename lconcl 	Domconcentrationl
rename lconcs  Domconcentrations

rename rodc5l 	ComDemDomconsl
rename rodc5s 	ComDemDomconss
rename roanc5l 	IncDemDomconsl
rename roanc5s 	IncDemDomconss
rename roatc5l 	ComAutDomconsl
rename roatc5s 	ComAutDomconss
rename rodnc5l 	IncAutDomconsl
rename rodnc5s  IncAutDomconss

rename lrgdem_  Regimel
rename smldem_  Regimes
rename mpA_ 	majpowl
rename mpB_ 	majpows
rename cwarA 	CivilWar
rename lconcen2 	Concap

global Controls Regimel Regimes majpowl majpows CivilWar Concap capratio_ allies_ contig_ distance_ iwaronspl iwaronsp1 iwaronsp2 iwaronsp3
set seed 12345
estsimp logit iwaron  IncDeml IncDems ComAutl ComAuts   Domconcentrationl Domconcentrations  IncDemDomconsl  IncDemDomconss  ComAutDomconsl  ComAutDomconss $Controls if bigwar==0, r
setx mean
setx  IncDeml 0 IncDems 0 ComAutl 0 ComAuts 0  Domconcentrationl 0 Domconcentrations  0 IncDemDomconsl 0 IncDemDomconss 0 ComAutDomconsl 0 ComAutDomconss  0 Regimel mean Regimes mean Concap mean capratio_ mean distance_ mean   majpowl 0 majpows 0 CivilWar 0 allies_ 0 contig_ 0  iwaronspl mean iwaronsp1 mean iwaronsp2 mean iwaronsp3 mean

forvalues i=0(1)9 {
di "Pr(WAR|Incomplete Democratization , Domconcentration l=`i'"
qui setx  IncDeml 0 IncDemDomconsl 0 Domconcentrationl `i' 
set seed 0
simqi, prval(1) genpr(piBASE`i')
}
generate DomConsAxis = _n -1 in 1/10
generate rrIncompleteDemoclMU =.
generate rrIncompleteDemoclLI =.
generate rrIncompleteDemoclHI =.
generate rrIncompleteDemocsMU =.
generate rrIncompleteDemocsLI =.
generate rrIncompleteDemocsHI =.

generate fdIncompleteDemoclMU =.
generate fdIncompleteDemoclLI =.
generate fdIncompleteDemoclHI =.
generate fdIncompleteDemocsMU =.
generate fdIncompleteDemocsLI =.
generate fdIncompleteDemocsHI =.

forvalues i=0(1)9 {
di "Pr(WAR|Incomplete Democratization , Domconcentration=`i'"
setx  IncDeml 0 IncDems 0 ComAutl 0 ComAuts 0  Domconcentrationl 0 Domconcentrations  0 IncDemDomconsl 0 IncDemDomconss 0 ComAutDomconsl 0 ComAutDomconss  0 Regimel mean Regimes mean Concap mean capratio_ mean distance_ mean   majpowl 0 majpows 0 CivilWar 0 allies_ 0 contig_ 0  iwaronspl mean iwaronsp1 mean iwaronsp2 mean iwaronsp3 mean
qui setx  IncDeml 1 Domconcentrationl `i' IncDemDomconsl `i'
set seed 0
simqi, prval(1) genpr(pi`i')
replace pi`i'=pi`i'/piBASE`i'
_pctile pi`i', p(2.5,97.5)
replace rrIncompleteDemoclLI = r(r1) if DomConsAxis==`i'
replace rrIncompleteDemoclHI = r(r2) if DomConsAxis==`i'
su pi`i'
replace rrIncompleteDemoclMU=r(mean) if DomConsAxis==`i'
drop pi`i'
simqi, prval(1) genpr(pi`i')
replace pi`i'=pi`i'-piBASE`i'
_pctile pi`i', p(2.5,97.5)
replace fdIncompleteDemoclLI = r(r1) if DomConsAxis==`i'
replace fdIncompleteDemoclHI = r(r2) if DomConsAxis==`i'
su pi`i'
replace fdIncompleteDemoclMU=r(mean) if DomConsAxis==`i'
drop pi`i'
}

forvalues i=0(1)9 {
di "Pr(WAR|Incomplete Democratization , Domconcentration=`i'"
setx  IncDeml 0 IncDems 0 ComAutl 0 ComAuts 0  Domconcentrationl 0 Domconcentrations  0 IncDemDomconsl 0 IncDemDomconss 0 ComAutDomconsl 0 ComAutDomconss  0 Regimel mean Regimes mean Concap mean capratio_ mean distance_ mean   majpowl 0 majpows 0 CivilWar 0 allies_ 0 contig_ 0  iwaronspl mean iwaronsp1 mean iwaronsp2 mean iwaronsp3 mean
qui setx  IncDems 1 Domconcentrations `i' IncDemDomconss `i'
set seed 0
simqi, prval(1) genpr(pi`i')
replace pi`i'=pi`i'/piBASE`i'
_pctile pi`i', p(2.5,97.5)
replace rrIncompleteDemocsLI = r(r1) if DomConsAxis==`i'
replace rrIncompleteDemocsHI = r(r2) if DomConsAxis==`i'
su pi`i'
replace rrIncompleteDemocsMU=r(mean) if DomConsAxis==`i'
drop pi`i'
simqi, prval(1) genpr(pi`i')
replace pi`i'=pi`i'-piBASE`i'
_pctile pi`i', p(2.5,97.5)
replace fdIncompleteDemocsLI = r(r1) if DomConsAxis==`i'
replace fdIncompleteDemocsHI = r(r2) if DomConsAxis==`i'
su pi`i'
replace fdIncompleteDemocsMU=r(mean) if DomConsAxis==`i'
drop pi`i'
}
preserve
{
keep DomConsAxis fd* rr*
keep if DomConsAxis!=.
saveold Figure1data.dta,replace
}
restore


******************************************************
************FIGURE 1**********************************
******************************************************

g yline=0 if DomConsAxis!=.

	   
twoway (line rrIncompleteDemoclMU DomConsAxis, clwidth(medium) clcolor(blue) clcolor(black))  ///
       (line rrIncompleteDemoclLI DomConsAxis, clpattern(dash) clwidth(thin) clcolor(red))  ///
       (line rrIncompleteDemoclHI DomConsAxis, clpattern(dash) clwidth(thin) clcolor(red))   ///
       (line yline DomConsAxis, clwidth(thin) clcolor(black) clpattern(dash)), ///
	   ytitle(Relative Risk) xtitle(Domestic Concentration) title(Relative Risk Side i) legend(off) scheme(s1mono) 

twoway (line fdIncompleteDemoclMU DomConsAxis, clwidth(medium) clcolor(blue) clcolor(black))  ///
       (line fdIncompleteDemoclLI DomConsAxis, clpattern(dash) clwidth(thin) clcolor(red))  ///
       (line fdIncompleteDemoclHI DomConsAxis, clpattern(dash) clwidth(thin) clcolor(red))   ///
       (line yline DomConsAxis, clwidth(thin) clcolor(black) clpattern(dash)), ///
	   ytitle(First Difference) xtitle(Domestic Concentration) title(First Difference Side i) legend(off) scheme(s1mono) 

twoway (line rrIncompleteDemocsMU DomConsAxis, clwidth(medium) clcolor(blue) clcolor(black))  ///
       (line rrIncompleteDemocsLI DomConsAxis, clpattern(dash) clwidth(thin) clcolor(red))  ///
       (line rrIncompleteDemocsHI DomConsAxis, clpattern(dash) clwidth(thin) clcolor(red))   ///
        (line yline DomConsAxis, clwidth(thin) clcolor(black) clpattern(dash)), ///
	   ytitle(Relative Risk) xtitle(Domestic Concentration) title(Relative Risk Side j) legend(off) scheme(s1mono) 


twoway (line fdIncompleteDemocsMU DomConsAxis, clwidth(medium) clcolor(blue) clcolor(black))  ///
       (line fdIncompleteDemocsLI DomConsAxis, clpattern(dash) clwidth(thin) clcolor(red))  ///
       (line fdIncompleteDemocsHI DomConsAxis, clpattern(dash) clwidth(thin) clcolor(red))   ///
       (line yline DomConsAxis, clwidth(thin) clcolor(black) clpattern(dash)), ///
	   ytitle(First Difference) xtitle(Domestic Concentration) title(First Difference Side j) legend(off) scheme(s1mono) 
/*
drop piBASE* b1-b25
relogit iwaron  IncDeml IncDems ComAutl ComAuts   Domconcentrationl Domconcentrations  IncDemDomconsl  IncDemDomconss  ComAutDomconsl  ComAutDomconss $Controls if bigwar==0,  pc(0.00031155) cluster(dyadid) 

forvalues i=0(1)9 {
setx  IncDeml 0 IncDems 0 ComAutl 0 ComAuts 0  Domconcentrationl 0 Domconcentrations  0 IncDemDomconsl 0 IncDemDomconss 0 ComAutDomconsl 0 ComAutDomconss  0 Regimel mean Regimes mean Concap mean capratio_ mean distance_ mean   majpowl 0 majpows 0 CivilWar 0 allies_ 0 contig_ 0  iwaronspl mean iwaronsp1 mean iwaronsp2 mean iwaronsp3 mean
relogitq, fd(pr) changex(IncDeml 0 1 IncDemDomconsl 0 `i' Domconcentrationl `i' `i')
replace fdIncompleteDemoclLI = r(dPrL_1) if DomConsAxis==`i'
replace fdIncompleteDemoclHI = r(dPrU_1) if DomConsAxis==`i'
replace fdIncompleteDemoclMU=r(dPr_1) if DomConsAxis==`i'
}

forvalues i=0(1)9 {
setx  IncDeml 0 IncDems 0 ComAutl 0 ComAuts 0  Domconcentrationl 0 Domconcentrations  0 IncDemDomconsl 0 IncDemDomconss 0 ComAutDomconsl 0 ComAutDomconss  0 Regimel mean Regimes mean Concap mean capratio_ mean distance_ mean   majpowl 0 majpows 0 CivilWar 0 allies_ 0 contig_ 0  iwaronspl mean iwaronsp1 mean iwaronsp2 mean iwaronsp3 mean
relogitq, fd(pr) changex(IncDems 0 1 IncDemDomconss 0 `i' Domconcentrations `i' `i')
replace fdIncompleteDemocsLI = r(dPrL_1) if DomConsAxis==`i'
replace fdIncompleteDemocsHI = r(dPrU_1) if DomConsAxis==`i'
replace fdIncompleteDemocsMU=r(dPr_1)  if DomConsAxis==`i'
}


twoway (line fdIncompleteDemoclMU DomConsAxis, clwidth(medium) clcolor(blue) clcolor(black))  ///
       (line fdIncompleteDemoclLI DomConsAxis, clpattern(dash) clwidth(thin) clcolor(red))  ///
       (line fdIncompleteDemoclHI DomConsAxis, clpattern(dash) clwidth(thin) clcolor(red))   ///
       (line yline DomConsAxis, clwidth(thin) clcolor(black) clpattern(dash)), ///
	   ytitle(First Difference) xtitle(Domestic Concentration) title(First Difference Side i) legend(off) scheme(s1mono) 
	

twoway (line fdIncompleteDemocsMU DomConsAxis, clwidth(medium) clcolor(blue) clcolor(black))  ///
       (line fdIncompleteDemocsLI DomConsAxis, clpattern(dash) clwidth(thin) clcolor(red))  ///
       (line fdIncompleteDemocsHI DomConsAxis, clpattern(dash) clwidth(thin) clcolor(red))   ///
       (line yline DomConsAxis, clwidth(thin) clcolor(black) clpattern(dash)), ///
	   ytitle(First Difference) xtitle(Domestic Concentration) title(First Difference Side j) legend(off) scheme(s1mono) 
*/
drop rr* fd* DomConsAxis
set seed 12345
sample 24394 if  iwaron==0, count
relogit iwaron  IncDeml IncDems ComAutl ComAuts   Domconcentrationl Domconcentrations  IncDemDomconsl  IncDemDomconss  ComAutDomconsl  ComAutDomconss $Controls if bigwar==0,  pc(0.00031155) cluster(dyadid) 

generate DomConsAxis = _n -1 in 1/10
generate fdIncompleteDemoclMU =.
generate fdIncompleteDemoclLI =.
generate fdIncompleteDemoclHI =.
generate fdIncompleteDemocsMU =.
generate fdIncompleteDemocsLI =.
generate fdIncompleteDemocsHI =.
generate rrIncompleteDemoclMU =.
generate rrIncompleteDemoclLI =.
generate rrIncompleteDemoclHI =.
generate rrIncompleteDemocsMU =.
generate rrIncompleteDemocsLI =.
generate rrIncompleteDemocsHI =.
forvalues i=0(1)9 {
set seed 12345
setx  IncDeml 0 IncDems 0 ComAutl 0 ComAuts 0  Domconcentrationl 0 Domconcentrations  0 IncDemDomconsl 0 IncDemDomconss 0 ComAutDomconsl 0 ComAutDomconss  0 Regimel mean Regimes mean Concap mean capratio_ mean distance_ mean   majpowl 0 majpows 0 CivilWar 0 allies_ 0 contig_ 0  iwaronspl mean iwaronsp1 mean iwaronsp2 mean iwaronsp3 mean
relogitq, fd(pr) changex(IncDeml 0 1 IncDemDomconsl 0 `i' Domconcentrationl `i' `i')
replace fdIncompleteDemoclLI = r(dPrL_1) if DomConsAxis==`i'
replace fdIncompleteDemoclHI = r(dPrU_1) if DomConsAxis==`i'
replace fdIncompleteDemoclMU=r(dPr_1) if DomConsAxis==`i'
set seed 12345
relogitq, rr(IncDeml 0 1 IncDemDomconsl 0 `i' Domconcentrationl `i' `i')
replace rrIncompleteDemoclLI = r(rrL_1) if DomConsAxis==`i'
replace rrIncompleteDemoclHI = r(rrU_1) if DomConsAxis==`i'
replace rrIncompleteDemoclMU=r(rr_1) if DomConsAxis==`i'

}

forvalues i=0(1)9 {
setx  IncDeml 0 IncDems 0 ComAutl 0 ComAuts 0  Domconcentrationl 0 Domconcentrations  0 IncDemDomconsl 0 IncDemDomconss 0 ComAutDomconsl 0 ComAutDomconss  0 Regimel mean Regimes mean Concap mean capratio_ mean distance_ mean   majpowl 0 majpows 0 CivilWar 0 allies_ 0 contig_ 0  iwaronspl mean iwaronsp1 mean iwaronsp2 mean iwaronsp3 mean
set seed 12345
relogitq, fd(pr) changex(IncDems 0 1 IncDemDomconss 0 `i' Domconcentrations `i' `i')
replace fdIncompleteDemocsLI = r(dPrL_1) if DomConsAxis==`i'
replace fdIncompleteDemocsHI = r(dPrU_1) if DomConsAxis==`i'
replace fdIncompleteDemocsMU=r(dPr_1)  if DomConsAxis==`i'
set seed 12345
relogitq, rr(IncDems 0 1 IncDemDomconss 0 `i' Domconcentrations `i' `i')
replace rrIncompleteDemocsLI = r(rrL_1) if DomConsAxis==`i'
replace rrIncompleteDemocsHI = r(rrU_1) if DomConsAxis==`i'
replace rrIncompleteDemocsMU=r(rr_1) if DomConsAxis==`i'
}
preserve
{
keep DomConsAxis fd* rr*
keep if DomConsAxis!=.
saveold Figure2data.dta,replace
}
restore

twoway (line fdIncompleteDemoclMU DomConsAxis, clwidth(medium) clcolor(blue) clcolor(black))  ///
       (line fdIncompleteDemoclLI DomConsAxis, clpattern(dash) clwidth(thin) clcolor(red))  ///
       (line fdIncompleteDemoclHI DomConsAxis, clpattern(dash) clwidth(thin) clcolor(red))   ///
       (line yline DomConsAxis, clwidth(thin) clcolor(black) clpattern(dash)), ///
	   ytitle(First Difference) xtitle(Domestic Concentration) title(First Difference Side i) legend(off) scheme(s1mono) 
	

twoway (line fdIncompleteDemocsMU DomConsAxis, clwidth(medium) clcolor(blue) clcolor(black))  ///
       (line fdIncompleteDemocsLI DomConsAxis, clpattern(dash) clwidth(thin) clcolor(red))  ///
       (line fdIncompleteDemocsHI DomConsAxis, clpattern(dash) clwidth(thin) clcolor(red))   ///
       (line yline DomConsAxis, clwidth(thin) clcolor(black) clpattern(dash)), ///
	   ytitle(First Difference) xtitle(Domestic Concentration) title(First Difference Side j) legend(off) scheme(s1mono) 

twoway (line rrIncompleteDemoclMU DomConsAxis, clwidth(medium) clcolor(blue) clcolor(black))  ///
       (line rrIncompleteDemoclLI DomConsAxis, clpattern(dash) clwidth(thin) clcolor(red))  ///
       (line rrIncompleteDemoclHI DomConsAxis, clpattern(dash) clwidth(thin) clcolor(red))   ///
       (line yline DomConsAxis, clwidth(thin) clcolor(black) clpattern(dash)), ///
	   ytitle(Relative Risk) xtitle(Domestic Concentration) title(First Difference Side i) legend(off) scheme(s1mono) 
	

twoway (line rrIncompleteDemocsMU DomConsAxis, clwidth(medium) clcolor(blue) clcolor(black))  ///
       (line rrIncompleteDemocsLI DomConsAxis, clpattern(dash) clwidth(thin) clcolor(red))  ///
       (line rrIncompleteDemocsHI DomConsAxis, clpattern(dash) clwidth(thin) clcolor(red))   ///
       (line yline DomConsAxis, clwidth(thin) clcolor(black) clpattern(dash)), ///
	   ytitle(Relative Risk) xtitle(Domestic Concentration) title(First Difference Side j) legend(off) scheme(s1mono) 

